Meta Build Tools

  • "Build tool for build tools".

  • Generate build files for other tools (do not compile directly).

  • Allow cross-platform configuration (Linux, Windows, macOS).

  • Use languages or DSLs (CMakeLists.txt, Meson.build, etc.).

  • "Great for working with different compilers in different types of systems".

CMake

  • CMake .

  • Cross-platform.

  • My version :

    • cmake-3.31.3-windows-x86_64.msi.

  • Can use Make, Ninja, etc.

Commands
  • cmake

    • Starts CMake.

  • -S "./../"

    • Sets the source directory  where the CMakeLists.txt  is.

    • Here: The source directory is the parent of the current directory ( ./../ ).

  • -B "vs2022_x64"

    • Sets the build directory  where CMake and Visual Studio generated files will be placed.

    • Here: vs2022_x64 .

  • -G "Visual Studio 17 2022"

    • Specifies the generator, i.e., the type of project to generate.

    • Here: Solution for Visual Studio 2022.

  • -A x64

    • Sets the build architecture .

    • Here: 64-bit.

  • -DCMAKE_INSTALL_PREFIX:String="SDK"

    • Sets the CMAKE_INSTALL_PREFIX  variable to "SDK" .

      • Defines the installation path for project artifacts (e.g., when running cmake --install  or the INSTALL  target).

    • Here: "SDK"  will be the installation prefix.

    • Note: :String  is redundant here. CMake correctly interprets -DVAR=VALUE  without type.

  • -DCMAKE_BUILD_TYPE:String=Distribution

    • Sets CMAKE_BUILD_TYPE  to "Distribution" .

      • Single-config builds (like Makefile or Ninja).

    • Note : Ignored in multi-config generators like Visual Studio, where build type (Debug/Release/etc.) is selected in the IDE or via --config .

  • %*

    • Inserts all arguments passed to the script/batch.

    • Allows passing additional arguments.

Breaking when moving
  • CMakeCache.txt  stores absolute paths to source and build directories.

  • Visual Studio project files generated by CMake (like .vcxproj ) also reference absolute paths.

  • If you move the folder, these paths become invalid, causing build errors or inability to open in Visual Studio.

  • Options :

    1. Recreate the build folder:

      • Delete the build folder (not the source folder).

      • Move the source folder to the new location.

      • Recreate the build directory in the new location:

        cmake .. -G "Visual Studio 17 2022"
        
      • Open the generated .sln  file in Visual Studio again.

    2. Delete all CMake-generated files.

      • CMakeCache.txt

      • CMakeFiles/

      • All .vcxproj , .sln , .user , .filters , etc.

      • Move the folder to the new location.

      • Reconfigure with CMake:

        cmake .. -G "Visual Studio 17 2022"
        
      • Not recommended :

        • Too many build artifacts (e.g., .o , .obj , .vcxproj , .sln , CMakeCache.txt , etc.) are placed inside the source directory.

        • Switching between different build systems or CMake options (e.g., different generators or toolchains) may cause conflicts.

        • Difficult to isolate multiple build configurations (e.g., Debug vs Release).

        • Some tools/scripts assume a clean separation of source and build.

    3. Use a separate build/  directory and always build out-of-source.

      • CMake documentation strongly encourages out-of-source builds.

Properties
  • CMake Properties .

  • CMake generates a .sln  and .vcxproj  with extra Visual Studio-specific information.

  • Ex :

    # Use solution folders to organize projects
    set_property(GLOBAL PROPERTY USE_FOLDERS ON)
    
Variables
    # Configure CMake global variables
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)


    set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Distribution")

Meson

  • Meson vs CMake .

    • Similar to CMake.

  • Needs to be used from Visual Studio CMD.

  • Modern alternative to CMake, generates Ninja  or Visual Studio .

Premake

  • Generates Makefile , Visual Studio , Xcode  from Lua scripts.

autotools

  • GNU.

  • Uses configure  + Makefile.in  to generate Makefile  (old, but still used).